import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';

import '../../config/route/bt_app_router.gr.dart';
import '../../data/stats/bt_log_pages.dart';
import '../../data/stats/bt_log_pv_manger.dart';

@RoutePage(name: "hostMainRoute")
class BtHostMainPage extends StatelessWidget {
  const BtHostMainPage({super.key});

  @override
  Widget build(BuildContext context) {
    return AutoTabsScaffold(
      routes: const [HomeRoute(), DiscoverRoute(), MessageRoute(), ProfileRoute()],
      bottomNavigationBuilder: (_, tabsRouter) {
        return BottomNavigationBar(
          showSelectedLabels: false,
          showUnselectedLabels: false,
          type: BottomNavigationBarType.fixed,
          currentIndex: tabsRouter.activeIndex,
          onTap: (index) {
            _onItemTapped(index, tabsRouter);
          },
          items: [
            BottomNavigationBarItem(
                label: '',
                icon: Image.asset(
                  'assets/images/bt_icon_coffee_default.png',
                  width: 26,
                  height: 24,
                ),
                activeIcon: Image.asset(
                  'assets/images/bt_icon_coffee_highlight.png',
                  width: 26,
                  height: 24,
                )),
            BottomNavigationBarItem(
                label: '',
                icon: Image.asset(
                  'assets/images/bt_icon_discover_default.png',
                  width: 26,
                  height: 24,
                ),
                activeIcon: Image.asset(
                  'assets/images/bt_icon_discover_highlight.png',
                  width: 26,
                  height: 24,
                )),
            BottomNavigationBarItem(
                label: '',
                icon: Image.asset(
                  'assets/images/bt_icon_msg_default.png',
                  width: 32,
                  height: 32,
                ),
                activeIcon: Image.asset(
                  'assets/images/bt_icon_msg_highlight.png',
                  width: 32,
                  height: 32,
                )),
            BottomNavigationBarItem(
                label: '',
                icon: Image.asset(
                  'assets/images/bt_icon_profile_default.png',
                  width: 32,
                  height: 32,
                ),
                activeIcon: Image.asset(
                  'assets/images/bt_icon_profile_highlight.png',
                  width: 32,
                  height: 32,
                )),
          ],
        );
      },
    );
  }

  void _onItemTapped(int index, TabsRouter tabsRouter) {
    tabsRouter.setActiveIndex(index);
    switch (index) {
      case 0:
        BtLogPvManger.stat(page: BtLogPages.tabHome);
        break;
      case 1:
        BtLogPvManger.stat(page: BtLogPages.tabFind);
        break;
      case 2:
        BtLogPvManger.stat(page: BtLogPages.tabChat);
        break;
      case 3:
        BtLogPvManger.stat(page: BtLogPages.tabMe);
        break;
    }
  }
}
